package com.yfbao.horizon.compress;

//import org.nustaq.serialization.FSTObjectInput;
//import org.nustaq.serialization.FSTObjectOutput;

import org.nustaq.serialization.FSTObjectInput;
import org.nustaq.serialization.FSTObjectOutput;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class FSTSerizlization {

    public static byte[] serialize(Object obj)  {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            FSTObjectOutput out = new FSTObjectOutput(baos);
            out.writeObject(obj);
            out.flush();
            out.close();
            return baos.toByteArray();
        }catch (IOException e){

        }
        return null;
    }

    public static Object deserialize(byte[] data) {
        try {
            ByteArrayInputStream bais = new ByteArrayInputStream(data);
            FSTObjectInput in = new FSTObjectInput(bais);
            Object obj = in.readObject();
            in.close();
            return obj;
        }catch (IOException|ClassNotFoundException e){
        }
        return null;
    }
}
